package cloud.take.off.mybatis.search;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

public enum Logic implements Serializable {

    /**
     * 模糊
     */
    like,

    /**
     * notLike
     */
    notLike,

    /**
     * 左模糊
     */
    likeLeft,

    /**
     * 又模糊
     */
    likeRight,

    /**
     * 在区间
     */
    in,

    /**
     * 不再区间
     */
    notIn,

    /**
     * 大于
     */
    gt,

    /**
     * 小于
     */
    lt,

    /**
     * 大于等于
     */
    ge,

    /**
     * 小于等于
     */
    le,

    /**
     * 等于
     */
    eq,

    /**
     * 不等于
     */
    ne;

    private static Map<Logic, Method> operationFuncMap = new HashMap();

    private Logic() {
    }

    public static Method getOperationFuncMap(Logic logic) {
        return (Method)operationFuncMap.get(logic);
    }

    public Method getOperationFuncMap() {
        return (Method)operationFuncMap.get(this);
    }

    public QueryWrapper addCondition(QueryWrapper wrapper, String column, Object value) {
        try {
            wrapper = (QueryWrapper)this.getOperationFuncMap().invoke(wrapper, column, value);
        } catch (IllegalAccessException var5) {
            var5.printStackTrace();
        } catch (InvocationTargetException var6) {
            var6.printStackTrace();
        }

        return wrapper;
    }

    static {
        Object[] logicValues = Logic.class.getEnumConstants();

        try {
            Object[] var1 = logicValues;
            int var2 = logicValues.length;

            for(int var3 = 0; var3 < var2; ++var3) {
                Object enumObj = var1[var3];
                Logic logic = (Logic)enumObj;
                if (logic.name() != "in" && logic.name() != "notIn") {
                    operationFuncMap.put(logic, QueryWrapper.class.getMethod(logic.name(), Object.class, Object.class));
                } else {
                    operationFuncMap.put(logic, QueryWrapper.class.getMethod(logic.name(), Object.class, Object[].class));
                }
            }
        } catch (NoSuchMethodException var6) {
            var6.printStackTrace();
        }

    }
}

